package longcaisuyun.longcai.com.yiliubabalongcaisuyun;


import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;
import android.widget.Toast;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilMD5;

import longcaisuyun.longcai.com.net.PostLogin;
import wh.activity.BaseSplash;
import wh.utils.StringUtils;

//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                            O\ = /O
//                        ____/`---'\____
//                      .   ' \\| |// `.
//                       / \\||| : |||// \
//                     / _||||| -:- |||||- \
//                       | | \\\ - /// | |
//                     | \_| ''\---/'' | |
//                      \ .-\__ `-` ___/-. /
//                   ___`. .' /--.--\ `. . __
//                ."" '< `.___\_<|>_/___.' >'"".
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |
//                 \ \ `-. \_ __\ /__ _/ .-` / /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//
//         .............................................
//         佛祖保佑             永无BUG
//         佛曰:
//                  写字楼里写字间，写字间里程序员；
//                  程序人员写程序，又拿程序换酒钱。
//                  酒醒只在网上坐，酒醉还来网下眠；
//                  酒醉酒醒日复日，网上网下年复年。
//                  但愿老死电脑间，不愿鞠躬老板前；
//                  奔驰宝马贵者趣，公交自行程序员。
//                  别人笑我忒疯癫，我笑自己命太贱；
//                  不见满街漂亮妹，哪个归得程序员？
/************************************************************/
//
/************************************************************/

public class WelcomeActivity extends BaseSplash {
    private Handler mHandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 0:
                    finish();
                    startActivity(new Intent(WelcomeActivity.this, LoginActivity.class));
                    break;
                case 1:
                    finish();
                    Toast.makeText(WelcomeActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
                    break;
                case 2:
                    finish();
                    startActivity(new Intent(WelcomeActivity.this, LoginActivity.class));
                    break;
                case 3:
                    finish();
                    startActivity(new Intent(WelcomeActivity.this, LoginActivity.class));
                    break;
            }
        }
    };
    @Override
    protected void setRootBackground(ImageView view) {
        view.setBackgroundResource(R.mipmap.appstart);

    }

    @Override
    protected void redirectTo() {
        if (StringUtils.isEmpty(MyApplication.myPreferences.readMobile())){
            skipActivity(this, LoginActivity.class);
        }else{
            new PostLogin(MyApplication.myPreferences.readMobile(), UtilMD5.MD5EncodeCount(MyApplication.myPreferences.readPassword(),"",2), new AsyCallBack<PostLogin.Info>() {
                public void onSuccess(String toast, int type, PostLogin.Info info) throws Exception {
                    super.onSuccess(toast, type, info);
                    String message = info.f;
                    if (message.equals("0")) {
                        mHandler.sendEmptyMessageDelayed(0,3000);
                    }
                    if (message.equals("1")) {
                        mHandler.sendEmptyMessageDelayed(1,3000);
                    }
                    if (message.equals("2")) {
                        mHandler.sendEmptyMessageDelayed(2,3000);
                    }
                    if (message.equals("3")) {
                        mHandler.sendEmptyMessageDelayed(3,3000);
                    }
                    if (message.equals("4")) {
                        Toast.makeText(WelcomeActivity.this, "您还未审核通过", Toast.LENGTH_SHORT).show();
                    }
                }

                public void onFail(String toast, int type) throws Exception {
                    super.onFail(toast, type);
                    finish();
                    startActivity(new Intent(WelcomeActivity.this, LoginActivity.class));
                }
            }).execute(WelcomeActivity.this);

        }
    }
}
